package com.example.demo;

import org.apache.spark.api.java.JavaSparkContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Scope;

import java.io.UnsupportedEncodingException;

@PropertySource("classpath:file.properties")
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    //生产bean
    @Bean(name = "sc")
    public JavaSparkContext makeSparkContext(){
        return new JavaSparkContext("local", "spark-container");
    }


    @Value("${filepath}")
    private String filepath;

    @Bean(name = "getFilePath")
    //@Scope(value = "prototype")
    public String getFilePath() throws UnsupportedEncodingException {
        return new String(this.filepath.getBytes("ISO-8859-1"),"UTF-8");
    }





}
